package com.kuang.controller;

import com.kuang.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: SpringMVC
 * @description:
 * @author: 陈恩涛
 * @create: 2020-08-08 07:08
 **/
@RestController
public class AjaxController {

    @RequestMapping("/testHealth")
    public List<String> test(){

        ArrayList<String> list = new ArrayList<>();
        list.add("111");
        list.add("222");


        return list;
    }

    @RequestMapping("/a1")
    public void a1(String name, HttpServletResponse response) throws IOException {
        System.out.println("name==>"+name);
        if("kuangshen".equals(name)){
            response.getWriter().println("true");
        }
        else
            response.getWriter().println("false");
    }

    @RequestMapping("/a2")
    public List<User> a2(){

        List<User> userList = new ArrayList<User>();
        userList.add(new User("陈恩涛",23,"男"));
        userList.add(new User("陈秋雨",21,"女"));
        userList.add(new User("陈学良",18,"男"));

        return userList;
    }

    @RequestMapping("/a3")
    public String a3(String name,String pwd){
        String msg = "";

        //这里的数据应该从数据库中取
        if(name!=null){
            if("admin".equals(name)){
                msg = "ok";
            }else{
                msg = "用户名有误";
            }
        }

        if(pwd!=null){
            if("123456".equals(pwd)){
                msg = "ok";
            }else{
                msg = "密码有误";
            }
        }

        return msg;
    }
}
